﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AsicMonitor
{
    public static class Helper
    {
        public static string ToDayTime(this string _input)
        {
            if(int.TryParse(_input, out int t))
            {
                t = t / 60;
                if( t < 60)
                {
                    return $"{t} 分";
                }
                int m = t % 60;
                t = t / 60;
                if( t < 24)
                {
                    return $"{t} 时 {m} 分";
                }

                int h = t % 24;
                t = t / 24;

                return $"{t} 天 {h} 时 {m} 分";
            }
            return "";
        }

        public static string ToHashrate(this string _input)
        {
            if(double.TryParse(_input, out double h))
            {
                h = h * 1024 * 1024;  // 放大到 M

                if(h < 1024)
                {
                    return $"{h} S";
                }
                h = Math.Round( h/ 1024, 2);
                if(h < 1024)
                {
                    return $"{h} K";
                }

                h = Math.Round(h / 1024, 2);
                if (h < 1024)
                {
                    return $"{h} M";
                }

                h = Math.Round(h / 1024, 2);
                if (h < 1024)
                {
                    return $"{h} G";
                }
                h = Math.Round(h / 1024, 2);
                if (h < 1024)
                {
                    return $"{h} T";
                }

                h = Math.Round(h / 1024, 2);
                if (h < 1024)
                {
                    return $"{h} P";
                }

                h = Math.Round(h / 1024, 2);
                if (h < 1024)
                {
                    return $"{h} E";
                }
            }
            return "";
        }

        public static string ToTemp(this string _input)
        {
            if(int.TryParse(_input, out int t))
            {
                return $"{t} ℃";
            }
            return "";
        }
    }
}
